﻿using System;
using System.Xml.Linq;

namespace EvoGame.Ceeforee.Helpers
{
	public static partial class Helper
	{
		public static class XML
		{
			public static XElement GetRawData(XElement xe, string tag)
			{
				XNamespace ns = xe.Name.Namespace;
				try
				{
					return xe.Element(ns.GetName(tag));
				}
				catch (NullReferenceException nre)
				{
					mWin.Debug = string.Format("Tag \"{0}\" is missing:{1}\t{2}", tag, Environment.NewLine, nre.Message);
					return null;
				}				
			}

			public static string GetStringData(XElement xe, string tag)
			{
				try
				{
					return GetRawData(xe, tag).Value;
				}
				catch (NullReferenceException nre)
				{
					mWin.Debug = string.Format("Tag \"{0}\" is missing:{1}\t{2}", tag, Environment.NewLine, nre.Message);
					return "NULL";
				}
			}

			public static bool GetBoolData(XElement xe, string tag)
			{
				return Convert.ToBoolean(int.Parse(GetStringData(xe, tag)));
			}

			public static int GetIntData(XElement xe, string tag)
			{
				return int.Parse(GetStringData(xe, tag));
			}

			public static float GetFloatData(XElement xe, string tag)
			{
				return float.Parse(GetStringData(xe, tag));
			}
		}
	}
}
